<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Wizard.Master" Inherits="System.Web.Mvc.ViewPage<SQLInstallationModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <% Html.RenderPartial("WizardHeader"); %>
    <%
        using (Html.BeginForm())
        { %>
    <h1>
        <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_Step1")%>
    </h1>
    <div>
        <% Html.EnableClientjQueryValidation();
           var existsOrNot = new List<SelectableNode>();
           existsOrNot.AddRange(new SelectableNode[] {
           new SelectableNode(HttpContext.GetGlobalResourceObject("language", "ConfigDB_CreateDB") as string,"true"),
           new SelectableNode(HttpContext.GetGlobalResourceObject("language", "ConfigDB_SelectExistsDB") as string,"false"),
           });
           var _engines = new List<SelectableNode>();
           _engines.AddRange(new SelectableNode[] {
           new SelectableNode("SQLServer 2008","SQLServer"),
           new SelectableNode(HttpContext.GetGlobalResourceObject("language", "ConfigDB_SQLExprDataFile") as string,"SQLDataFile"),
           });
        %>
        <%:Html.AntiForgeryToken()%>
        <%:Html.ValidationSummary()%>
    </div>
    <% if (ViewData["Error"] != null)
       { %>
    <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
        <p>
            <span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
            <strong>
                <%:HttpContext.GetGlobalResourceObject("language", "RES_ERR") %>:</strong><%:ViewData["Error"] %></p>
    </div>
    <%} %>
    <div style="margin: 10px; overflow: auto;">
        <div style="margin-top: 10px;">
            <label for="ServerName">
                <b>
                    <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_SQLDBEngine") %></b> -<%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_SQLDBEngine_Title")%></label>
        </div>
        <div>
            <%:Ajax.DropDown("DataBaseEngine", _engines,
                new DropDownOptions()
                {
                    OnClientSelectedChanged = "changeDataBaseEngine(ui.value);",
                    SelectedValue = "SQLServer",
                    Width = 200
                })%></div>
        <div style="margin-top: 10px;" id="createInstanceAction">
            <%:Ajax.DropDown("IsCreateNewInstance", existsOrNot,
                new DropDownOptions()
                {
                    OnClientSelectedChanged = "changeCreateInstanceAction(ui.value);",
                    SelectedValue = "true",
                    Width = 200
                })%>
        </div>
        <h3>
            <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_SQLSRV_Info")%>
        </h3>
        <div style="clear: left; margin-top: 10px;">
            <div style="margin-top: 10px;">
                <label for="ServerName">
                    <b>
                        <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_SRV_Name")%></b> -<%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_SRV_Title")%>
                </label>
            </div>
            <div>
                <% Html.ValidateFor(m => m.ServerName);%>
                <%:Ajax.TextBox("ServerName", Environment.MachineName)%></div>
            <div style="margin-top: 10px;">
                <label for="DataBaseName">
                    <b>
                        <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_DB_Name")%></b> -
                    <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_DB_Title")%></label></div>
            <div>
                <%:Ajax.TextBox("DataBaseName", "DNADB")%><% Html.ValidateFor(m => m.DataBaseName); %></div>
        </div>
        <div id="connOnly" style="display: none; overflow: auto; margin-top: 10px; margin-bottom: 5px;">
            <%:Ajax.CheckBox("IsGenerateConnectionOnly", HttpContext.GetGlobalResourceObject("language", "ConfigDB_GenerateCnn") as string, false)%>
        </div>
        <h3 style="clear: left;">
          <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_UserAndPwd")%></h3>
        <div style="margin-top: 10px;">
            <%:Ajax.CheckBox("IntegratedSecurity", new CheckBoxOptions()
                {
                    Text =HttpContext.GetGlobalResourceObject("language", "ConfigDB_IntegratedSecurity") as string,
                    Value = Model != null ? Model.IntegratedSecurity : true,
                    OnCheckedChanged = "if (value) $('#explicitlyIdentity').hide(); else $('#explicitlyIdentity').show();"
                })
            %>
            <div style="clear: left;">
            </div>
        </div>
        <div id="explicitlyIdentity" style="display:none;">
            <div style="margin-top: 10px;">
                <div>
                   <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_UserName_Title")%>
                </div>
                <div>
                    <%:Ajax.TextBox("UserName", Model != null ? Model.UserName : "")%><% Html.ValidateFor(m => m.UserName); %></div>
            </div>
            <div style="margin-top: 10px;">
                <div>
                 <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_Password_Title")%></div>
                <div>
                    <%:Ajax.Password("Password", "")%><% Html.ValidateFor(m => m.Password); %></div>
            </div>
            <div style="margin-top: 10px;">
                <div>
                    <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_Password_Confirm")%></div>
                <div>
                    <%:Ajax.Password("ConfirmPassword", "")%><% Html.ValidateFor(m => m.ConfirmPassword); %></div>
            </div>
        </div>
        <div id="admin_part" style="margin-top: 10px;">
            <h3>
               <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_Admin_UserAndPWD")%></h3>
            <div>
                <%:Ajax.CheckBox("IsWindowIdentity", new CheckBoxOptions()
                      {
                          Text = HttpContext.GetGlobalResourceObject("language", "ConfigDB_IntegratedSecurity")  as string,
                          Value = true,
                          OnCheckedChanged = "if (value) $('#sqladmin').hide(); else $('#sqladmin').show();"
                      })
                %>
                <div style="clear: left;" />
            </div>
            <div id="sqladmin" style="display:none;">
                <div style="margin-top: 10px;">
                    <div>
                        <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_SQLAdmin_User")%></div>
                    <div>
                        <%:Ajax.TextBox("SQLAdminName", Model != null ? Model.SQLAdminName : "sa")%><% Html.ValidateFor(m => m.SQLAdminName); %></div>
                </div>
                <div style="margin-top: 10px;">
                    <div>
                        <%:HttpContext.GetGlobalResourceObject("language", "ConfigDB_SQLAdmin_PWD")%></div>
                    <div>
                        <%:Ajax.Password("SQLAdminPassword", "")%></div>
                </div>
            </div>
        </div>
    </div>
    <div style="margin-top: 10px; padding: 10px;" class="ui-widget-content ui-border-top">
        <%:Ajax.Submit(HttpContext.GetGlobalResourceObject("language", "RES_NEXT") as string)%>
    </div>
    <%} %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        function changeDataBaseEngine(value) {
            if (value == 'SQLDataFile') {
                $('#createInstanceAction').hide();
                $('#connOnly').show(); $('#admin_part').hide();
                $('#ServerName').val('.\\SQLExpress');
                $('#DataBaseName').val('DataBase.mdf');
            }
            else {
                $('#createInstanceAction').show();
                changeCreateInstanceAction($("#IsCreateNewInstance").dropdown("option", "selectedValue"));
            }
        }

        function changeCreateInstanceAction(value) {
            if (value == "true") {
                $('#admin_part').show();
                $('#connOnly').hide();
            }
            else {
                $('#admin_part').hide();
                $('#connOnly').show();
            }
        }
    </script>
</asp:Content>
